package cn.itcast.crm.service.impl;

import java.util.List;

import org.apache.cxf.jaxrs.client.WebClient;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.crm.dao.CustomerDao;
import cn.itcast.crm.domain.Customer;
import cn.itcast.crm.service.CustomerService;
@Service
@Transactional
public class CustomerServiceImpl implements CustomerService {
	//注入Dao层
	@Autowired
	private CustomerDao cd;
	@Override
	
	public List<Customer> findNoFixedAreaId() {
		// TODO Auto-generated method stub
		return cd.findByFixedAreaIdIsNull();
	}

	@Override
	public List<Customer> findHasFixedAreaId(String fixedAreaId) {
		// TODO Auto-generated method stub
		return cd.findByFixedAreaId(fixedAreaId);
	}

	@Override
	public void saveFixedAreaId(String customerIdStr, String fixedAreaId) {
		//切割前台传送的字符串
		String[] split = customerIdStr.split(",");
		for (String string : split) {
			Integer id = Integer.parseInt(string);
			cd.updateFixedAreaId(fixedAreaId, id);
		}
	}

	@Override
	public void regist(Customer c) {
		System.out.println(c);
		cd.save(c);
	}

	@Override
	public Customer findByTelephone(String telephone) {
			Customer customer = cd.findByTelephone(telephone);
		return customer;
	}

	@Override
	public void updateType(String telephone) {
		cd.updateType(telephone);
	}

	@Override
	public Customer login(String telephone, String password) {
		Customer customer = cd.findByTelephoneAndPassword(telephone,password);
		return customer;
	}
	//根据地址查找定区ID
	@Override
	public String findFixedAreaIdByAddress(String address) {
		return cd.findFixedAreaIdByAddress(address);
	}

}
